package com.hl.card.modular.packBack.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hl.card.common.util.HttpURLClient;
import com.hl.card.common.util.ResponseData;
import com.hl.card.modular.packBack.service.GoodsSevice;
import com.hl.card.modular.packBack.service.FreezingManageService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class FreezingManageServiceImpl implements FreezingManageService {
    //支付中心接口的地址
    @Value("${dismemberapply.pay.baseUrl}")
    private String baseUrl;

       @Autowired
       private ResponseData responseData;

       @Resource
       private GoodsSevice goodsSevice;

       @Value("${dismemberapply.ka_ip}")
       private String ip;  //卡包项目IP

       /**
        *   比豆交易记录
        */
   @Override
   public JSONObject queryfreezingManage(Integer start, Integer end, String dealCreateTime, String dealEndTime,
           String productType, String merchantOrderNumber, String dealRecordNumber, String userPhone,String goodsCode) {
       // TODO Auto-generated method stub
               Map<String,String> paramMap=new HashMap<String, String>();
               paramMap.put("start", start + "");
                  paramMap.put("end", end + "");
                  if(dealCreateTime!=null&&dealCreateTime!=""){
                  paramMap.put("dealCreateTime", dealCreateTime);
                      }
                  if(dealEndTime!=null&&dealEndTime!=""){
                       paramMap.put("dealEndTime", dealEndTime);
                      }
                  if( productType!=null&&productType!=""){
                      paramMap.put("productType", productType);
                      }
                  if(merchantOrderNumber!=null&&merchantOrderNumber!=""){
                      paramMap.put("merchantOrderNumber", merchantOrderNumber);
                      }
                  if(dealRecordNumber!=null&&dealRecordNumber!=""){
                      paramMap.put("dealRecordNumber", dealRecordNumber);
                      }
                  if(userPhone!=null&&userPhone!=""){
                      paramMap.put("userPhone", userPhone);
                  }
       String result = HttpURLClient.post(paramMap, baseUrl + "/api/saDealRecord/list");
       JSONObject json = JSONObject.parseObject(result);
       List<Map<String, Object>> list= goodsSevice.selectList();
        JSONArray res = json.getJSONArray("list");
       JSONArray resNew = new JSONArray();
        String dealEndTimeItem = "";
        for (int i = 0; i < res.size(); i++) {
//			 if (list.size() > 0) {
//				 String imb = ((Goods) list.get(0)).getGoodsCode();
//				 res.getJSONObject(i).put("goodsCode", imb);
//				 System.out.println(imb);
//				 System.out.println(list);
//				 System.out.println(res);
//				 System.out.println(json);
//			 }
            JSONObject temp = (JSONObject) res.get(i);
            dealEndTimeItem = temp.getString("dealEndTime");
            if(StringUtils.isBlank(dealEndTimeItem)) {
                resNew.add(temp);
            }
        }
       json.put("list", resNew);
       /*JSONObject json = JSONObject.parseObject(result);
       json = json.getJSONObject("list");
       String goodsCode = json.getString("productType");
                Goods goods = goodsSevice.selectByCode(goodsCode);
                String prodName = goods.getGoodsName();*/
                responseData.setData(JSONObject.parse(json.toJSONString()));
                responseData.setMsg("操作成功");
                responseData.setStatus("1");

               return JSONObject.parseObject(json.toJSONString());

   }
/*		return json;

 }*/
}